class HttpApi {
	request(url, method, params) {
		uni.showLoading({
			title: '加载中',
		})
		uni.stopPullDownRefresh()
		return new Promise((resolve, reject) => {
			const BASE_API = 'http://codercba.com:9002'
			uni.request({
				url: BASE_API + url,
				method: method,
				data: params,
				success: function(res) {
					uni.hideLoading()
					resolve(res.data)
				},
				fail: function(err) {
					uni.hideLoading()
					reject(err)
				}
			})
		})
	}
	// 封装get请求
	get(url, params) {
		return this.request(url, 'GET', params)
	}
	// 封装post请求
	post(url, params) {
		return this.request(url, 'POST', params)
	}
}

const httpApi = new HttpApi()

export default httpApi
